public class Hash {
    public class Node{
        public int key;
        public int val;
        public Node next;

        public Node(int key,int val){
            this.key = key;
            this.val = val;
        }
    }

    public Node array[];
    public int usedsize;
    public double Usedfactor = 0.75;
    public Hash(){
        array =  new Node[10];
    }

    public void push(int key,int val){
        int index = key % array.length;
        Node cur = array[index];
        while (cur != null){
            if (cur.key == key){
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        Node node = new Node(key,val);
        node.next = array[index];
        array[index] = node;
        usedsize++;
        if (usedvalfactor() > Usedfactor){
            //进行扩容操作
            resize();
        }
    }
    public void resize(){
        Node[] newarray = new Node[array.length *2];
        for (int i = 0; i < array.length; i++) {
            Node cur = array[i];
            while (cur != null){
                int newindex = cur.key % newarray.length;
                Node curn = cur.next;
                cur.next = newarray[newindex];
                newarray[newindex] = cur;
                cur = curn;
            }
        }
        array = newarray;
    }

    public int get(int key){
        int index = key % array.length;
        Node cur = array[index];
        while (cur != null){
            if (cur.key == key){
                return cur.val;
            }
            cur = cur.next;
        }
        return -1;
    }
    public double usedvalfactor(){
        return usedsize *1.0 / array.length;
    }
}

